package com.haiyisoft.eclipse.uep.generate.simple.wizard;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardNode;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.graphics.Point;

import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.AjaxformPageWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.BlankSceneWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.FreeformPageWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.ListFreeformPageWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.ListPageWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.MultiPageWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.TreeTableWizard;
import com.haiyisoft.eclipse.uep.generate.simple.webpage.wizard.TreegridPageWizard;

/**
 * WizardNode
 * 
 * @author sly 2011-05-04
 * 
 */
public class WebPageWizardNode implements IWizardNode {

	private Wizard wizard;

	private int index;
	
	private  IStructuredSelection selection;

	public WebPageWizardNode(IStructuredSelection selection,int index) {
		super();
		this.index = index;
		this.selection = selection;
	}

	public Point getExtent() {
		return new Point(-1, -1);
	}

	public IWizard getWizard() {
		if ((wizard == null)) {
			if (index == 0)
				wizard = new BlankSceneWizard(selection);
			else if (index == 1)
				wizard = new ListPageWizard(selection);
			else if(index == 2)
				wizard = new FreeformPageWizard(selection);
			else if(index == 3)
				wizard = new ListFreeformPageWizard(selection);
			else if(index == 4)
				wizard = new MultiPageWizard(selection);
			else if(index == 5)
				wizard = new TreeTableWizard(selection);
			else if(index == 6)
				wizard = new TreegridPageWizard(selection);
			else if(index == 7)
				wizard = new AjaxformPageWizard(selection);
		}
		return wizard;
	}

	public boolean isContentCreated() {
		return wizard != null;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof WebPageWizardNode))
			return false;
		WebPageWizardNode node = (WebPageWizardNode) obj;
		return index == node.index;
	}

	public int hashCode() {
		return String.valueOf(index).hashCode();
	}

	public void dispose() {
		if (wizard != null)
			wizard.dispose();
	}

}
